/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elcom.emocbc.dbmapping.persistence;

import java.sql.Connection;
import org.jooq.ConnectionProvider;
import org.jooq.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author GiangLT
 */
public class DbConnectionProvider implements ConnectionProvider {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public Connection acquire() throws DataAccessException {
        try {
            return DbAccess.getInstance().getConnection();
        } catch (Exception ex) {
            logger.error("", ex);
            return null;
        }
    }

    @Override
    public void release(Connection connection) throws DataAccessException {
//        DbAccess.commitTransaction(connection);
        DbAccess.closeConnection(connection);
    }
}
